﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace DXApplicationTangche.UC.订单一览新.销售确认单
{
    public partial class Form销售日记账每日预览 : DevExpress.XtraEditors.XtraForm
    {
        public Form销售日记账每日预览()
        {
            InitializeComponent();
        }

        private void dateTimePicker时间_CloseUp(object sender, EventArgs e)
        {
            this.查询();
        }

        private void dateTimePicker结束时间_CloseUp(object sender, EventArgs e)
        {
            this.查询();
        }
        private void 查询()
        {
            this.pivotGridControl销售日记账每日预览.DataSource =
                new Model销售日记账每日预览(
                    this.dateTimePicker起始时间.Value.ToString("yyyy-MM-dd"),
                this.dateTimePicker结束时间.Value.ToString("yyyy-MM-dd")
                )
                .saleConfirmQueryTitileVOs;
            this.pivotGridControl销售日记账每日预览.Refresh();
        }

        private void simpleButtonPDF_Click(object sender, EventArgs e)
        {
            new Form销售日记账预览(
                this.dateTimePicker起始时间.Value.ToString("yyyy-MM-dd"),
                this.dateTimePicker结束时间.Value.ToString("yyyy-MM-dd")
                ).ShowDialog();
        }
    }
    public class Model销售日记账每日预览
    {
        public List<SaleConfirmQueryTitileVO> saleConfirmQueryTitileVOs = new List<SaleConfirmQueryTitileVO>();
        public Model销售日记账每日预览(String dateTimeStart, String dateTimeEnd)
        {
            List<SaleConfirmQueryTitileDTO> saleConfirmQueryTitileDTOs =
                销售确认Service.getSaleConfirmListByDateTimeStr(dateTimeStart, dateTimeEnd);
            foreach (SaleConfirmQueryTitileDTO item in saleConfirmQueryTitileDTOs)
            {
                this.saleConfirmQueryTitileVOs.Add(new SaleConfirmQueryTitileVO(item));
            }
        }
    }
    public class SaleConfirmQueryTitileVO
    {
        public String id { get; set; }    //
        public String quoteId { get; set; }    //  应用分录id
        public String mobile { get; set; }    //   客户电话
        public String customerName { get; set; }   //客户姓名
        public String customer { get; set; }   //客户
        public DateTime orderDate { get; set; }    //  日期
        public String businessType { get; set; }    // 业务类型    SalesTypeConsts
        public String barcode { get; set; }    //  成衣码
        public String refBarcode { get; set; }    //   参考成衣码
        public String styleNameCn { get; set; }    //  款式
        public String materialCode { get; set; }    // 面料
        public String materialNameCn { get; set; }  //面料名称
        public String styleSizeCd { get; set; }    //  尺码
        public Double price { get; set; }    //    金额
        public int quantity { get; set; }    //    数量
        public String store { get; set; }    //    销售组织
        public String storeName { get; set; }    //    销售组织name
        public String assistant { get; set; }    //    负责人
        public String assistantName { get; set; }    //    负责人name
        public String remarks { get; set; }    //  备注
        public Boolean synchronize { get; set; }    //  是否同步销售订单
        public Boolean deprecated { get; set; } //  是否作废
        public String saleOrderDetailId { get; set; }  //  销售分录ID
        public String manufactureOrderId { get; set; }  //  生产订单id
        /**
         * 调价
         */
        public Double adjustPrice { get; set; } //  调整价格
        /**
         * 设计
         */
        public Double designPrice { get; set; } //  设计费用
        public Double finalPrice { get; set; } //  最终价格

        public List<SaleConfirmQueryDetailDTO> saleConfirmQueryDetailDTOList { get; set; } = new List<SaleConfirmQueryDetailDTO>();
        public SaleConfirmQueryTitileVO(SaleConfirmQueryTitileDTO dto)
        {
            this.id = dto.id;
            this.quoteId = dto.quoteId;
            this.mobile = dto.mobile;
            this.customerName = dto.customerName;
            this.customer = dto.customerName + " " + dto.mobile;
            this.orderDate = dto.orderDate;
            this.businessType = dto.businessType;    // 业务类型
            this.barcode = dto.barcode;    //  成衣码
            this.refBarcode = dto.refBarcode;    //   参考成衣码
            this.styleNameCn = dto.styleNameCn;    //  款式
            this.materialCode = dto.materialCode;    // 面料
            this.materialNameCn = dto.materialNameCn;  //面料名称
            if (!String.IsNullOrWhiteSpace(dto.styleSizeCd))
            {
                try { this.styleSizeCd = dto.styleSizeCd.Replace("IGS_GROUP_SIZE-", "").Replace("EGS_GROUP_SIZE-", ""); } catch { }
            }
            this.price = dto.price;    //    金额
            this.quantity = dto.quantity;    //    数量
            this.store = dto.store;    //    销售组织
            this.storeName = dto.storeName;    //    销售组织name
            this.assistant = dto.assistant;    //    负责人
            this.assistantName = dto.assistantName;    //    负责人name
            this.remarks = dto.remarks;    //  备注
            this.synchronize = dto.synchronize;    //  是否同步销售订单
            this.deprecated = dto.deprecated; //  是否作废
            this.saleOrderDetailId = dto.saleOrderDetailId;  //  销售分录ID
            this.manufactureOrderId = dto.manufactureOrderId;  //  生产订单id
            this.adjustPrice = dto.adjustPrice; //  调整价格
            this.designPrice = dto.designPrice; //  设计费用
            this.finalPrice = dto.price * dto.quantity + dto.designPrice + dto.adjustPrice; //  设计费用
        }
    }
}